< previous page page_214 next page >

Page 214
You need a bit of code to enable the Print Setup command button. Notice that you set the Flags property to &H40. This forces the common dialog box to display the Printer Setup dialog box. Here's the code:
Private Sub cmdPrnSetup_Click ()
   CMDialog1.Flags = &H40 ' force the printers setup dialog box
   CMDialog1.Action = 5 ' run the printer setup
End Sub
The code for the OK command button is the most involved of the form. This routine performs input validation, sets final report properties, sets up an error trap, and then runs the Crystal Reports Pro report. The input validation should look familiar. Note that an additional input validation test had to be invented to check the combo box. After the validation pass, a few properties of the report control are set. Afterwards, the report is generated.
The report run is wrapped in an error-trapping routine. Error trapping is covered in greater detail next week. For now, you should note that after the error trap is turned on, the code attempts to erase the output filename, if necessary, and then runs the report. Once the report is done, the error trapping is turned off.
The error routine is simple. It displays a Message box for any error encountered, except for the error that occurs when the user attempts to erase a file that does not exist. Here's the code:
Private Sub cmdOK_Click ()
   Dim nOK As Integer ' validation results
   Dim nVldErr As Integer ' validation pass/fail flag
   Dim cMsg As String ' report error string
   Dim cTitle As String ' error title
   '
   ' perform validation
   If CrystalReport1.Destination = 2 Then
      nOK = IsValid(txtFileName, "Save File Name", True)
      If nOK = False Then
         nVldErr = True
      End If
      '
      If cboFileTypes.ListIndex = -1 Then
         MsgBox "Missing Print File Type", 0, "Validation Error"
         cboFileTypes.SetFocus
         nVldErr = True
      End If
   End If
   '
   ' did we find an error?
   If nVldErr = True Then
      GoTo OKExit ' leave now!
   End If

   '
   ' set some final parameters
   CrystalReport1.WindowTitle = txtWindowTitle ' set the window title

 
< previous page page_214 next page >

If you like this book, buy it!